package com.xiyu.service.controller.admin.material;
import com.xiyu.service.vo.material.transfer.TransferSingleGetDetailOutput;
import com.xiyu.service.vo.material.transfer.TransferUpdateStatusInput;
import com.xiyu.service.vo.material.transfer.TransferSingleGetOutput;
import com.xiyu.service.vo.material.transfer.TransferUpdateInput;
import com.xiyu.service.vo.material.transfer.TransferCreateInput;
import com.xiyu.service.vo.material.transfer.TransferPageQueryOutput;
import com.xiyu.service.vo.material.transfer.TransferPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.material.TransferService;

@Tag(name = "调拨单管理")
@RestController
@RequestMapping("/material/transfer")
@Validated
public class TransferController {

    @Resource
    private TransferService transferService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询调拨单")
    @PreAuthorize("@ss.hasPermission('material:transfer:query')")
    public CommonResult<PageResult<TransferPageQueryOutput>> pageQuery(@Valid TransferPageQueryInput inputVO) {
        return success(transferService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增调拨单")
    @PreAuthorize("@ss.hasPermission('material:transfer:create')")
    public CommonResult<Long> create(@Valid @RequestBody TransferCreateInput inputVO) {
        return success(transferService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新调拨单")
    @PreAuthorize("@ss.hasPermission('material:transfer:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody TransferUpdateInput inputVO) {
        return success(transferService.update(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个调拨单")
    @Parameter(name = "id", description = "物资调拨单主键ID", example = "")
    public CommonResult<TransferSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(transferService.singleGet(id));
    }

    @PutMapping("/update-status")
    @Operation(summary = "更新调拨单状态")
    public CommonResult<Boolean> updateStatus(@Valid @RequestBody TransferUpdateStatusInput inputVO) {
        return success(transferService.updateStatus(inputVO));
    }

    @GetMapping("/single-get-detail")
    @Operation(summary = "获取单个调拨单明细")
    @Parameter(name = "transferId", description = "物资调拨单ID", example = "")
    public CommonResult<List<TransferSingleGetDetailOutput>> singleGetDetail(@RequestParam("transferId") Long transferId) {
        return success(transferService.singleGetDetail(transferId));
    }

}
